﻿using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;

/// <summary>
/// 提示面板
/// </summary>
public class TipView : ViewBase
{
    /// <summary>
    /// 提示标题
    /// </summary>
    private Text title;
    /// <summary>
    /// 提示内容
    /// </summary>
    private Text content;

    /// <summary>
    /// 按钮0
    /// </summary>
    private Button btn0;

    /// <summary>
    /// 按钮1
    /// </summary>
    private Button btn1;
    string str = "";

    #region 生命周期

    //初始化
    public override void Init(params object[] args)
    {
        base.Init(args);
        layer = PanelLayer.Tips;
        //参数 args[1]代表提示的内容
        if (args.Length == 1)
        {
            str = (string)args[0];
        }
    }

    //显示之前
    public override void OnShowing()
    {
        base.OnShowing();
        Transform skinTrans = panelObj.transform;
        title = skinTrans.Find("Title").GetComponent<Text>();
        content = skinTrans.Find("Content").GetComponent<Text>();
        content.text = str;
        btn0 = skinTrans.Find("Btns/0").GetComponent<Button>();
        btn0.onClick.AddListener(OnClose);
        btn1 = skinTrans.Find("Btns/1").GetComponent<Button>();
        btn1.onClick.AddListener(OnClose);
    }
    #endregion

    public void ShowOne(UnityAction a)
    {
        btn0.onClick.AddListener(a);
        btn1.gameObject.SetActive(false);
    }

    public void ShowTwo(UnityAction a, UnityAction b)
    {
        btn0.onClick.AddListener(a);
        btn1.onClick.AddListener(b);
    }

    public void OnClose()
    {
        Close();
    }
}